package com.codefish;

/**
 * 收银台类，模拟收银台，对应Context
 *
 * @author codefish
 * @version 1.0
 * @date 2022/05/07 下午 03:09
 */
public class CashCounter {
    /**
     * 商品折扣方法
     */
    private IDiscount discount;

    public CashCounter() {
        //设置默认打折策略为不打折
        discount = new NoDiscount();
    }

    /**
     * 设置折扣策略
     * @param discount 折扣策略
     */
    public void setDiscount(IDiscount discount) {
        this.discount = discount;
    }

    /**
     * 计算实付价格
     *
     * @param price 商品原价
     * @return 顾客应付价格
     */
    public double countPrice(double price) {
        //计算折扣
        double discountVal = discount.countDiscount(price);
        //返回应付价格
        return price - discountVal;
    }

}
